/** eslint-disable */
import CryptoJS from 'crypto-js'

export const config = {
  secretKey: import.meta.env.VITE_APP_TECENT_SECRETKEY,
  secretId: import.meta.env.VITE_APP_TECENT_SECRETID,
  appId: import.meta.env.VITE_APP_TECENT_APPID
}

/** 获取签名 start */

function toUint8Array(wordArray) {
  // Shortcuts
  const words = wordArray.words
  const sigBytes = wordArray.sigBytes

  // Convert
  const u8 = new Uint8Array(sigBytes)
  for (let i = 0; i < sigBytes; i++) {
    u8[i] = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff
  }
  return u8
}

function Uint8ArrayToString(fileData) {
  let dataString = ''
  for (let i = 0; i < fileData.length; i++) {
    dataString += String.fromCharCode(fileData[i])
  }
  return dataString
}
// 签名函数示例
export function signCallback(signStr) {
  const secretKey = config.secretKey
  const hash = CryptoJS.HmacSHA1(signStr, secretKey)
  const bytes = Uint8ArrayToString(toUint8Array(hash))
  return window.btoa(bytes)
}

/** 获取签名 end */
